package com.durian.finance.controller;

import com.durian.common.core.utils.poi.ExcelUtil;
import com.durian.common.core.web.controller.BaseController;
import com.durian.common.core.web.domain.AjaxResult;
import com.durian.common.core.web.page.TableDataInfo;
import com.durian.common.log.annotation.Log;
import com.durian.common.log.enums.BusinessType;
import com.durian.common.security.annotation.RequiresPermissions;
import com.durian.finance.service.IJrFactoringDetailService;
import com.durian.financial.api.domain.JrFactoringDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 保理申请明细Controller TODO
 * 
 * @author durian
 * @date 2022-06-27
 */
@RestController
@RequestMapping("/factoringDetail")
public class JrFactoringDetailController extends BaseController
{

    @Autowired
    private IJrFactoringDetailService jrFactoringDetailService;


    /**
     * 查询保理申请明细列表
     */
    @RequiresPermissions("finance:factoring:list")
    @GetMapping("/list")
    public TableDataInfo list(JrFactoringDetail jrFactoringDetail)
    {
        startPage();
        List<JrFactoringDetail> list = jrFactoringDetailService.selectJrFactoringDetailList(jrFactoringDetail);
        return getDataTable(list);
    }

    /**
     * 导出保理申请明细列表
     */
    @RequiresPermissions("finance:factoring:export")
    @Log(title = "保理申请明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JrFactoringDetail jrFactoringDetail)
    {
        List<JrFactoringDetail> list = jrFactoringDetailService.selectJrFactoringDetailList(jrFactoringDetail);
        ExcelUtil<JrFactoringDetail> util = new ExcelUtil<JrFactoringDetail>(JrFactoringDetail.class);
        util.exportExcel(response, list, "保理申请明细数据");
    }

    /**
     * 获取保理申请明细详细信息
     */
    @RequiresPermissions("finance:factoring:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(jrFactoringDetailService.selectJrFactoringDetailById(id));
    }

    /**
     * 新增保理申请明细
     */
    @RequiresPermissions("finance:factoring:add")
    @Log(title = "保理申请明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JrFactoringDetail jrFactoringDetail)
    {
        return toAjax(jrFactoringDetailService.insertJrFactoringDetail(jrFactoringDetail));
    }

    /**
     * 修改保理申请明细
     */
    @RequiresPermissions("finance:factoring:edit")
    @Log(title = "保理申请明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JrFactoringDetail jrFactoringDetail)
    {
        return toAjax(jrFactoringDetailService.updateJrFactoringDetail(jrFactoringDetail));
    }

    /**
     * 删除保理申请明细
     */
    @RequiresPermissions("finance:factoring:remove")
    @Log(title = "保理申请明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jrFactoringDetailService.deleteJrFactoringDetailByIds(ids));
    }
}
